package com.subumbo.keyboard
{
	import flash.events.KeyboardEvent;
	
	public class Key
	{
		public var keys:Array;
		
		static private var _instance:Key;
		
		static public function get Instance():Key
		{
			if(!_instance) _instance = new Key();
			return _instance;
		}
		
		public function Key()
		{
			keys = new Array(7);
		}
		
		public function downhandle(obj:KeyboardEvent):void
		{
			keys[obj.keyCode] = true;
		}
		public function uphandle(obj:KeyboardEvent):void
		{
			keys[obj.keyCode] = false;
		}
		public function isDown(keyCode:uint, ...keyCodes):Boolean
		{
			if(keyCodes.length==0)
				return keys[keyCode];
			else
			{
				if(!keys[keyCode]) return false;
				for(var i:uint = 0; i<keyCodes.length; ++i)
				{
					if(!keys[keyCodes[i]]) return false;
				}
				return true;
			}
		}
		
		public function isUp(keyCode:uint, ...keyCodes):Boolean
		{
			if(keyCodes.length==0)
				return !keys[keyCode];
			else
			{
			if(keys[keyCode]) return false;
			for(var i:uint = 0; i<keyCodes.length; ++i)
			{
				if(keys[keyCodes[i]]) return false;
			}
			return true;
			}
		}
		
		
	}
}